package com.shop.admin.controller;

import com.shop.admin.entity.ShopSlideshow;
import com.shop.admin.result.ApiResult;
import com.shop.admin.service.ShopSlideshowService;
import com.shop.admin.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

@Api(tags = {"ShopSlideshowController"},description = "零食轮播图接口")
@RestController
@RequestMapping("/api/slideshow")
public class ShopSlideshowController {

    @Resource
    private ShopSlideshowService shopSlideshowService;
    /**
     * 轮播图列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "get轮播图列表",notes = "page,limit,orgId")
    public ApiResult list(@ApiParam("参数为：page,limit,组织id")@RequestParam Map<String, Object> params){
        PageUtils page = shopSlideshowService.queryPage(params);
        return ApiResult.ok(page);
    }

    /**
     * 轮播图修改and新增
     */
    @PostMapping("/update")
    @ApiOperation(value = "轮播图修改and新增",notes = "id,图片路径，跳转路径")
        public ApiResult slideshowUpdate(@ApiParam("参数为：id,imgurl,clickhref")@RequestBody ShopSlideshow slideshow){
        shopSlideshowService.updateSlideshow(slideshow);
        return ApiResult.ok("操作成功！");
    }

    /**
     * 轮播图删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "轮播图删除",notes = "id数组")
    public ApiResult delete(@ApiParam("参数为：Id[]")@RequestBody Long[] ids){
        shopSlideshowService.removeMenuByIds(Arrays.asList(ids));
        return ApiResult.ok("删除成功！");
    }
}
